package com.ciaojian.store.pay;

import com.ciaojian.core.model.Store;
import com.ciaojian.core.model.WxPayBase;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author oxiny
 */
@Component
public class WxPayBeanFactory {
    /**
     * 获取配置信息
     */
    @Resource
    private WxPayBean wxPayBean;
    @Resource
    private WxPayBean2 wxPayBean2;
    @Resource
    private WxPayBean3 wxPayBean3;

    private static WxPayBase staticWxPayBean;
    private static WxPayBase staticWxPayBean2;
    private static WxPayBase staticWxPayBean3;

    @PostConstruct
    public void init() {
        staticWxPayBean = wxPayBean;
        staticWxPayBean2 = wxPayBean2;
        staticWxPayBean3 = wxPayBean3;
    }

    /**
     * 根据情况返回微信支付配置
     *
     * @param store 门店
     * @param type  类型 0返回剪发商户 1返回会员卡商户
     * @return 微信支付配置
     */
    public static WxPayBase getInstance(Store store, int type) {
        if (store == null) {
            return staticWxPayBean2;
        }
        // 如果门店是加盟店
        if (store.getType() == 2) {
            return staticWxPayBean3;
        } else if (type == 0) {
            return staticWxPayBean;
        } else {
            return staticWxPayBean2;
        }
    }

    /**
     * 获取剪发商户
     */
    public static WxPayBase getWxPayBean() {
        return staticWxPayBean;
    }

}
